function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
	
	draw.SimpleText( "j", "CSSelectIcons", x + wide/2, y + tall*0.2, Color( 255, 110, 0, 255 ), TEXT_ALIGN_CENTER )
	draw.SimpleText( "j", "CSSelectIcons", x + wide/2 + math.Rand(-4, 4), y + tall*0.2+ math.Rand(-9, 9), Color( 255, 110, 0, math.Rand(10, 120) ), TEXT_ALIGN_CENTER )
	
end

if ( CLIENT ) then

	SWEP.ViewModelFOV		= 72
	SWEP.ViewModelFlip		= false
	SWEP.CSMuzzleFlashes	= false
	
	killicon.AddFont( "weapon_stalkerknife", "CSKillIcons", "j", Color( 255, 80, 0, 255 ) )

end

SWEP.Author = "";
SWEP.Contact = "";
SWEP.Purpose = "";
SWEP.Instructions = ""; 

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= true

SWEP.Primary.Recoil			= 1.25
SWEP.Primary.Damage			= 50
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.02
SWEP.Primary.Delay			= .81

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "none"

SWEP.Secondary.Delay		= .5
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= true
SWEP.Secondary.Ammo			= "none"

SWEP.ViewModel = "models/weapons/v_knife_t.mdl"
SWEP.WorldModel = "" --NONE

util.PrecacheSound("weapons/knife/knife_hitwall1.wav")
util.PrecacheSound("weapons/knife/knife_slash1.wav")
util.PrecacheSound("weapons/knife/knife_stab.wav")
util.PrecacheSound("weapons/knife/knife_deploy1.wav")
util.PrecacheSound("ambient/machines/slicer1.wav")
util.PrecacheSound("ambient/machines/slicer4.wav")
util.PrecacheSound("ambient/machines/slicer2.wav")
util.PrecacheSound("npc/stalker/go_alert2.wav") -- REEEH
util.PrecacheSound("UI/buttonclickrelease.wav") -- Stealth noise
 
util.PrecacheSound("physics/flesh/flesh_impact_bullet2.wav") -- Stealth noise

held = {entity = nil, physics = nil, physicsBone = nil}

function SWEP:Deploy()
	self.Weapon:EmitSound("weapons/knife/knife_deploy1.wav")
	self.Weapon:SendWeaponAnim( ACT_VM_DEPLOY )
	
		if held.entity then
		held.entity:SetNetworkedString("heldprop","no")
		held.entity = nil
		end
	held.entity = nil
end

function SWEP:Holster()
	self.Weapon:SendWeaponAnim( ACT_VM_DEPLOY )
	
		if held.entity then
		held.entity:SetNetworkedString("heldprop","no")
		held.entity:SetCollisionGroup(COLLISION_GROUP_NONE)
		held.entity = nil
		end
	held.entity = nil
end

function SWEP:Initialize()
    if (CLIENT) then return end
    self:SetWeaponHoldType("slam")
    held.entity = nil
end 

function SWEP:OwnerChanged()
	held.entity = nil
end
 
function SWEP:Reload()
end
 
function SWEP:Think()
	if held.entity == nil then
		return
	end
	if !held.entity:IsValid() or !held.physics:IsValid() or !held.entity then
		held.entity = nil
	elseif held.entity then
    	local pos = self.Owner:GetShootPos()
    	local ang = self.Owner:GetAimVector() + Vector(0, 0, 0.13) 
		
		if held.entity:GetModel() == "models/police.mdl" then
			held.physics:SetPos(pos + (ang * 39))
		else
			held.physics:SetPos(pos + (ang * 49))
		end
			
	end
end

function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire( CurTime() + 0.50 )

	if held.entity != nil then
		self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
		if held.entity:GetModel() == "models/police.mdl" then
			-- corpse
			held.entity:SetCollisionGroup(COLLISION_GROUP_WEAPON)
			self.Owner:EmitSound(Sound("physics/flesh/flesh_impact_bullet2.wav"),100,120)
			
			local tr2tb = {}
			tr2tb.start = held.entity:GetPos()
			tr2tb.endpos = tr2tb.start + (self.Weapon:GetOwner():GetAimVector() * 20)
			//tr2tb.filter = { self.Weapon:GetOwner(), tr.Entity }
			tr2tb.mask = 1
			local tr2 = util.TraceLine( tr2tb )
			
			if tr2.Hit and !tr2.Entity:IsPlayer() then
				-- pin it 
				local rpos = held.entity:GetPos()
					if not util.IsInWorld(rpos) then
					
					local tra3 = util.GetPlayerTrace(self.Owner)
					local tr3 = util.TraceLine(tra3)
					
					held.entity:SetPos(tr3.HitPos)
					
					end
				local pos = tr2.HitPos-- + tr2.HitNormal * 6--self.Owner:GetShootPos() - (self.Owner:GetAimVector() * 6)
				local ang = self.Owner:GetAimVector():Angle()
				held.entity:SetPos(tr2.HitPos + Vector(0,0,0))
				util.Decal("Blood", held.entity:GetPos() - self.Owner:GetAimVector(), held.entity:GetPos() + self.Owner:GetAimVector())
				pos = held.entity:WorldToLocal(pos)
				held.entity:SetPos(tr2.HitPos)
				local constraint = CorpsePin(held.entity, tr2.Entity, held.physicsBone, tr2.PhysicsBone, 0, pos, ang)
				held.entity:SetNetworkedString("heldprop","no")
				held.entity = nil
				return
			end
		else
			-- other
			held.entity:SetCollisionGroup(COLLISION_GROUP_NONE)
			self.Weapon:EmitSound(Sound("weapons/knife/knife_hitwall1.wav"))
		end
		
		local rpos = held.entity:GetPos()
		
			if not util.IsInWorld(rpos) then
					
			local tra3 = util.GetPlayerTrace(self.Owner)
			local tr3 = util.TraceLine(tra3)
					
			held.entity:SetPos(tr3.HitPos)
					
			end
		
		self.Weapon:EmitSound(Sound("weapons/knife/knife_slash1.wav"))
		held.physics:ApplyForceCenter(self.Owner:GetAimVector() * 30000)
		held.entity:SetNetworkedString("heldprop","no")
		held.entity = nil
		return
	end

	self.Owner:LagCompensation(true)
 	local trace = util.GetPlayerTrace(self.Owner)
 	local tr = util.TraceLine(trace)
	self.Owner:LagCompensation(false)

	if (trace.start - tr.HitPos):Length() > 100 then
		-- too far away
		self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
		self.Weapon:EmitSound(Sound("weapons/knife/knife_slash1.wav"))
		return
	end

	if tr.HitWorld then
		util.Decal("ManhackCut", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
		self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
		self.Weapon:EmitSound(Sound("weapons/knife/knife_hitwall1.wav"))
		self.Weapon:EmitSound(Sound("weapons/knife/knife_slash1.wav"))
		self.Owner:ViewPunch(Angle( math.Rand(-3,3) * self.Primary.Recoil, math.Rand(-3,3) * self.Primary.Recoil, 0 ) )
	elseif tr.HitNonWorld and tr.MatType == MAT_GLASS then
	self.Weapon:EmitSound(Sound("weapons/knife/knife_hitwall1.wav"))
	self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
	return
	elseif tr.Entity:IsPlayer() then
		self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
		self.Owner:ViewPunch(Angle( math.Rand(-3,3) * self.Primary.Recoil, math.Rand(-3,3) * self.Primary.Recoil, 0 ) )
		util.Decal("Blood", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
		if (SERVER) then
			if tr.Entity:Health() >= 51 then
				tr.Entity:EmitSound(RandomSound(StabHurt))
			end
			tr.Entity:TakeDamage(self.Primary.Damage + math.random(1,15),self.Owner) 
			local effectdata = EffectData()
			effectdata:SetOrigin(tr.HitPos)
			effectdata:SetNormal(tr.HitNormal)
			util.Effect("bodyshot", effectdata)
		end
		self.Weapon:EmitSound(Sound(RandomSound(Wep_Slice)))
		self.Weapon:EmitSound(Sound("weapons/knife/knife_slash1.wav"))
	else
		local physobj = tr.Entity:GetPhysicsObject()
		if physobj:IsValid() then
			if physobj:GetMass() <= 370 and !tr.Entity:IsConstrained() and !tr.Entity:IsPlayer() then
				held.entity = tr.Entity
				held.entity:SetNetworkedString("heldprop","yes")
				held.entity:SetCollisionGroup(COLLISION_GROUP_WEAPON)
				held.physics = physobj
				held.physics:ApplyForceCenter(self.Owner:GetAimVector() * 666)
				held.physicsBone = tr.PhysicsBone
			end
		end
	end
end
 
StabHurt = {
"npc/combine_soldier/pain1.wav",
"npc/combine_soldier/pain2.wav",
"npc/combine_soldier/pain3.wav",
"npc/metropolice/pain1.wav",
"npc/metropolice/pain2.wav",
"npc/metropolice/pain3.wav",
"npc/metropolice/pain4.wav",
"npc/metropolice/knockout2.wav"}

Wep_Slice = {
	"ambient/machines/slicer1.wav",
	"ambient/machines/slicer2.wav",
	"ambient/machines/slicer4.wav",
	"weapons/knife/knife_stab.wav"}
 
function CorpsePin( Ent1, Ent2, Bone1, Bone2, forcelimit, Pos, Ang )

	//local trace = util.GetPlayerTrace(self.Owner,Vector(0,0,1))
 	//local trc = util.TraceLine(trace)
	
	trace={}
	trace.start=Ent1:GetPos()+Vector(0,0,-5)
	trace.endpos=trace.start+Vector(0,0,1000)
	trc=util.TraceLine(trace) 

	local effectdata = EffectData()
	effectdata:SetOrigin(trc.HitPos) -- ceiling
	effectdata:SetNormal(trc.HitNormal)
	util.Effect("bloodsplash", effectdata)
	util.Effect("bloodsplash", effectdata)
	
	return constraint.Weld( Ent1, Ent2, Bone1, Bone2, forcelimit )
end
  

 function SWEP:SecondaryAttack()
	
 end